package day12;

import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.DefaultHandler;

/**
 * @author oldliu
 * @since 1.0
 */
public class MyHandler extends DefaultHandler {
    @Override
    public void characters(char[] ch, int start, int length) throws SAXException {
        System.out.println("文本内容："+new String(ch,start,length));
    }

    @Override
    public void startDocument() throws SAXException {
        System.out.println("文档开始了");
    }

    @Override
    public void endDocument() throws SAXException {
        System.out.println("读完了xml");
    }

    @Override
    public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException {
        System.out.println(localName+","+uri+","+qName+",右属性："+attributes.getLength()+"个");
        for(int i=0;attributes!=null && i<attributes.getLength();i++){
            System.out.println(attributes.getQName(i)+"="+attributes.getValue(i));
        }
    }

    @Override
    public void endElement(String uri, String localName, String qName) throws SAXException {
        System.out.println(qName+"结束了");
    }
}
